@namespace MudBlazor.UnitTests.TestComponents

<MudTreeView T="TreeItemData" ServerData="LoadServerData" Items="TreeItems" Hover="true" Width="100%">
    <ItemTemplate Context="item">
        <MudTreeViewItem T="TreeItemData" Value="@item" CanExpand="true" Icon="@Icons.Material.Filled.Label">
            <BodyContent>
                <div class="mud-treeview-item-bodycontent" style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%;">
                    <MudText Style="justify-self: start;">@item.Title</MudText>
                    <div style="justify-self: end;">
                        <MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Medium" Color="Color.Inherit" />
                        <MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" />
                    </div>
                </div>
            </BodyContent>
        </MudTreeViewItem>
    </ItemTemplate>
</MudTreeView>

@code{
    public HashSet<TreeItemData> TreeItems { get; set; } = new HashSet<TreeItemData>();
    public bool SimulateUpdateRoot = false;
    public bool SimulateUpdate3 = false;

    public class TreeItemData
    {
        public string Title { get; set; }

        public TreeItemData(string title)
        {
            Title = title;
        }
    }

    protected override async Task OnInitializedAsync()
    {
        TreeItems = await LoadServerData(null);
    }

    public Task<HashSet<TreeItemData>> LoadServerData(TreeItemData parentNode)
    {
        if (parentNode == null)
        {
            if (SimulateUpdateRoot == false)
                return Task.FromResult(new HashSet<TreeItemData>()
                {
                    new TreeItemData("This is item one"),
                    new TreeItemData("This is item two"),
                    new TreeItemData("This is item three"),
                    new TreeItemData("This is item six")
                });
            else
                return Task.FromResult(new HashSet<TreeItemData>()
                {
                    new TreeItemData("This is item one"),
                    new TreeItemData("This is item 2"),
                    new TreeItemData("This is item three"),
                    new TreeItemData("This is item six")
                });
        }
        else if (parentNode.Title == "This is item three")
        {
            if (SimulateUpdate3 == false)
                return Task.FromResult(new HashSet<TreeItemData>()
                {
                    new TreeItemData("This is item four"),
                    new TreeItemData("This is item five"),
                });
            else
                return Task.FromResult(new HashSet<TreeItemData>()
                {
                    new TreeItemData("This is item 4"),
                    new TreeItemData("This is item 5"),
                });
        }
        else
        {
            return Task.FromResult(new HashSet<TreeItemData>());
        }
    }
}
